//
//  UIWidget.cpp
//  CocosLib
//
//  Created by wangdi on 13-8-1.
//
//

#include "UIWidget.h"
#include <cassert>

using namespace cocos2d;

namespace storm
{
    UIWidget *UIWidget::s_pFocusWidget = NULL;
    
    UIWidget::UIWidget()
        : m_bEnable(true)
    {
    }
    
    //-------------------------------------------------------------------------/
    UIWidget::~UIWidget()
    {
        loseFocus();
    }
    
    bool UIWidget::isContainsTouch(cocos2d::CCTouch *pTouch)
    {
     
        if(!m_bEnable || !isVisible())
        {
            return false;
        }
        return (cocos2d::CCRect(-this->getContentSize().width*0.5f, -this->getContentSize().height*0.5f, this->getContentSize().width, this->getContentSize().height).containsPoint(this->convertTouchToNodeSpace(pTouch)));
        
    }
    
    
    void UIWidget::fadeOut(float duration)
    {
        for(std::vector<cocos2d::CCNode *>::iterator iter = m_vFadeNodes.begin(); iter != m_vFadeNodes.end(); iter++)
        {
            ((CCNode *)(*iter))->runAction(cocos2d::CCFadeOut::create(duration));
        }
    }
    void UIWidget::fadeIn(float duration)
    {
        for(std::vector<cocos2d::CCNode *>::iterator iter = m_vFadeNodes.begin(); iter != m_vFadeNodes.end(); iter++)
        {
            ((CCNode *)(*iter))->runAction(cocos2d::CCFadeIn::create(duration));
        }
    }
   
    
    
}